﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business;
using System.Text;
using NHibernate.Criterion;
using NHibernate;
using System.Collections;
using ZLCMS.Data.Model;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business.Config;
using Newtonsoft.Json;
using System.Reflection;
using ZLCMS.Business.Util;
using ZLCMS.Business.TranferParam;
using DotNet.Common.TransferParam;

namespace ZLCMS.Web.SystemManage.Basics.Shop.MemberCard
{
    public partial class MemberCardBinding : System.Web.UI.Page
    {
        public WxMemberCard card { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            ZLCMS.Business.DwzFrame.FrameHelper _framePage = new ZLCMS.Business.DwzFrame.FrameHelper(this);
            ZLCMS.Business.DwzFrame.ReturnCode rc;
         
            if (!IsPostBack)
            {
                //设置对象
              
                
                int uid = 0;
                if (int.TryParse(Request["uid"], out uid))
                {
                    using (NHibernate.ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                    {
                        card = session.Get<WxMemberCard>(uid);
                        if (card != null)
                        {
                            //保存uid
                            ViewState["uid"] = uid;

                            txt_card_no.Text = card.BindingCardNo;
                        }
                    }
                }
            }
            else
            {
                using (NHibernate.ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                {
                    if (ViewState["uid"] == null || ViewState["uid"] == "")
                    {
                        card = new WxMemberCard();
                    }
                    else
                    {
                        card = session.Get<WxMemberCard>(ViewState["uid"]);
                    }
                    card.BindingCardNo = txt_card_no.Text;

                    session.SaveOrUpdate(card);
                    session.Flush();
                }
            

            //框架返回成功提示
            rc = new ZLCMS.Business.DwzFrame.ReturnCode()
           {
               statusCode = 200,
               message = "操作成功"
           };
            rc.callbackType = "closeCurrent";


            _framePage.Alert(rc);
            }
        }
    }
}